package com.jy.adscm.zltx.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.zltx.bean.SjFile;
import com.jy.adscm.zltx.bean.SjFileVersionRecord;
import com.jy.adscm.zltx.mapper.mysql.SjFileMapper;
import com.jy.adscm.zltx.mapper.mysql.SjFileVersionRecordMapper;
import com.jy.adscm.zltx.service.SjFileVersionRecordService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-11-08
 */
@Service
public class SjFileVersionRecordServiceImpl extends ServiceImpl<SjFileVersionRecordMapper, SjFileVersionRecord> implements SjFileVersionRecordService {
     @Autowired
    JyUserMapper jyUserMapper;
     @Autowired
     SjFileMapper sjFileMapper;
    @Override
    public List<SjFileVersionRecord> selectByFileId(Integer fileId) {
        SjFile sjFile = sjFileMapper.selectById(fileId);
        Wrapper<SjFileVersionRecord> wrapper =new EntityWrapper<>();
        wrapper.eq("fileId",fileId);
        List<SjFileVersionRecord> sjFileVersionRecords = super.selectList(wrapper);
        for (SjFileVersionRecord sjFileVersionRecord : sjFileVersionRecords) {
            if (sjFileVersionRecord.getIssuer()!=null&&!"".equals(sjFileVersionRecord.getIssuer())){
                JyUser jyUser = jyUserMapper.selectById(sjFileVersionRecord.getIssuer());
               sjFileVersionRecord.setIssuerName(jyUser.getName());
            }
            sjFileVersionRecord.setFileName(sjFile.getFileName());
        }
        return sjFileVersionRecords;
    }
}
